package com.dingup.provider.service.permission.impl;

import com.dingup.api.model.sys.SysPermission;
import com.dingup.api.model.sys.SysPermissionGroup;
import com.dingup.provider.mapper.SysPermissionGroupMapper;
import com.dingup.provider.mapper.SysPermissionMapper;
import com.dingup.provider.service.permission.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by wancheng on 2018/8/8.
 */
@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    SysPermissionGroupMapper sysPermissionGroupMapper;
    @Autowired
    SysPermissionMapper sysPermissionMapper;

    @Override
    public List<SysPermissionGroup> getByPermissionByUserId(String userId) {
        List<SysPermissionGroup> groups = sysPermissionGroupMapper.getUserPermissionGroupByUserId(userId);
        groups.stream().forEach(
                group -> {
                    List<SysPermission> permissions = sysPermissionMapper.getByGroupId(group.getId());
                    group.setPermissionUrl(permissions);

                });
        return groups;
    }
}
